using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.CSharp;

namespace Objectinator
{
    public class Namespace
    {
        private readonly string name;
        private readonly List<Class> classes = new List<Class>();

        public Namespace(string name)
        {
            this.name = name;
        }

        public string Code
        {
            get
            {
                CodeNamespace namespaceDeclaration = new CodeNamespace(name);
                foreach (Class c in classes)
                {
                    c.AddDeclaration(namespaceDeclaration);
                }
                StringBuilder stringBuilder = new StringBuilder();
                CSharpCodeProvider codeProvider = new CSharpCodeProvider();
                codeProvider.GenerateCodeFromNamespace(namespaceDeclaration, new StringWriter(stringBuilder), new CodeGeneratorOptions());
                return stringBuilder.ToString();
            }
        }

        public void AddType(Class c)
        {
            classes.Add(c);
        }
    }
}